-
Notifications
You must be signed in to change notification settings - Fork 2k
[lexical] Bug Fix: Remove Paragraph Replacement in HeadingNode
#7846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
I'm not really sure why this is here - it seems both semantically incorrect in all the cases I've observed and also causes bugs in other Lexical functions, as if they keep a reference to the `HeadingNode` that is replaced, subsequent usage of that `HeadingNode` will cause errors. See a common example of this in `RangeSelection#insertNodes()` in the added test.
|
I think this code exists so if you have a document that starts with a HeadingNode and move the cursor to the beginning of the document and press return then it will add an empty ParagraphNode before the HeadingNode instead of creating a second HeadingNode. I don't know why it does that (AFAICT Google Docs and Word do not behave like that), but I think that's the purpose. @zurfyx any historical knowledge here? Maybe there's a bug where the selection anchor and focus isn't fixed up correctly during this operation, or insertNodes is holding on to a node reference longer than it should rather than going back to the selection. Those sorts of bugs could be fixed without changing the behavior here (and probably also fix other issues with other nodes that just haven't been reported yet). |
|
Note that there is an e2e test that is expecting the current behavior which fails https://github.com/facebook/lexical/actions/runs/17925833260/job/50971623711?pr=7846 |
|
FWIW, I believe Maybe the reference should be updated there via another call to I think as a user I would personally prefer to match Docs and Word, but fixing the invariant bug is the main concern. |
|
I think that's right, it should be a |
|
Took a stab at it, but need some help. Trying to restore it based on the selected child does not seem to work, as the node we actually want to insert children into is the previous empty paragraph. I'm a bit confused why Maybe it does need to use previous sibling instead? But also seems weird that now |
Things like `insertParagraph` can remove `firstBlock` from the editor state, so re-compute it in those cases.
|
If I randomly add a I'm going to let someone who understands the intent of the code better take a look. Happy to make changes if given suggestions around what correct behavior should look like here. |
|
So far as anyone remembers this decision was opinion-based and fairly arbitrary. Changing the behavior to match other popular text editors (google docs, word, etc.) would be fine, but of course the tests also have to change to match the updated behavior and the PR description should be updated to note the breaking change. |
Description
I'm not really sure why this
HeadingNodecode exists - it seems both semantically incorrect in all the cases I've observed and also causes bugs in other Lexical functions, as if they keep a reference to theHeadingNodethat is replaced, subsequent usage of thatHeadingNodewill cause errors. See a common example of this inRangeSelection#insertNodesin the added test.Also moved other regression tests to bottom of file. I can move this test case somewhere else if more appropriate.
Test plan
Test included - fails with invariant before this test.
Before
After
Test passes.